package Library.operation;

import Library.Book;
import Library.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除书籍");
        Scanner scanner = new Scanner(System.in);
        int index = scanner.nextInt();
        if(index < 0 || index > bookList.getSize() -1){
            System.out.println("输出错误");
            return;
        }
        if(index == bookList.getSize() - 1){
            bookList.setSize(bookList.getSize() - 1);
        } else {
            Book lastbook = bookList.getBook(bookList.getSize() - 1);
            bookList.setBook(index,lastbook);
            bookList.setSize(bookList.getSize() - 1);
        }
        System.out.println("删除书籍成功");
    }
}
